package com.atguigu.jxc.controller;


import com.alibaba.fastjson.JSON;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.ReturnList;
import com.atguigu.jxc.entity.ReturnListGoods;
import com.atguigu.jxc.service.ReturnListService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/returnListGoods")
public class ReturnListController {
    @Autowired
    ReturnListService returnListService;


    /**
        方法的作用: 退货单列表展示
        开发时间： 2023-02-11 9:11
        是否已经开发完毕：
        是否有功能可以拓展：
        @Param String returnNumber,Integer supplierId, Integer state,String sTime,String eTime

    */
    @PostMapping("/list")
    public Map<String,Object> ShowReturnList (String returnNumber,Integer supplierId, Integer state,String sTime,String eTime){
        List<ReturnList> returnLists = returnListService.ShowReturnList(returnNumber,supplierId,state,sTime,eTime);
        HashMap<String,Object> map = new HashMap<>();
        map.put("rows",returnLists);
        return map;
    }

    /**
        方法的作用:退货单商品信息
        开发时间： 2023-02-11 15:10
        是否已经开发完毕：
        是否有功能可以拓展：
    */
    @PostMapping("/goodsList")
    public Map<String,Object> ShowReturnListGoods (Integer returnListId ){
        List<ReturnListGoods> returnListGoods =returnListService.showReturnListGoods(returnListId);
        HashMap<String,Object> map =new HashMap<>();
        map.put("rows",returnListGoods);
        return map;
    }

    @PostMapping("/delete")
    public ServiceVO DeleteReturnListGoods (Integer returnListId){
        ServiceVO serviceVO = returnListService.deleteReturnListGoods(returnListId);
        return serviceVO;
    }
    //http://localhost:8080/returnListGoods/count
    @PostMapping("/count")
    public String count(String sTime, String eTime ,Integer goodsTypeId, String codeOrName){
        List<Map<String,Object>> list = returnListService.count(sTime,eTime,goodsTypeId,codeOrName);
        return JSON.toJSONString(list);
    }


}
